/*
Kakine
ActionScript Framework
Copyright © 2011, PUNY, LLC.

This file is part of KAKINE.

KAKINE is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

KAKINE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KAKINE.  If not, see <http://www.gnu.org/licenses/>.
*/ 
package com.puny.utils.easing
{
	public class OneEndEasing extends Easing implements IEasing
	{
		private var _x0:Number;
		private var _length:Number;
		private var _order:Number;
		private var _half:Number;
		private var _first:Boolean = true;
		/**
		 * 
		 * @param start Start number
		 * @param end End number
		 * @param count The number of frames
		 * @param order Absolute number of this one is Easing order. If this is a negative number, easing happens around the end. Otherwise, it happens around the start.
		 * 
		 */
		public function OneEndEasing(start:Number, end:Number, count:uint, order:int)
		{
			_first = order >= 0;
			frame = count;
			_x0 = start;
			_length = end - start;
			_order = _first ? order : -order;
			initialize();
		}
		
		
		public function forward():Number
		{
			var pp:Number;
			if (isMoving()) {
				pos++;
				if (_first) {
					pp = _length * f(pos/frame) + _x0;
				} else {
					pp = _length *(1 - f(1-pos/frame)) + _x0;
				}
			} else {
				pp = _x0 + _length;
			}
			return pp;
		}
				
		private function f(x:Number):Number {
			var y:Number = 1;
			for(var i:int = 0;i < _order;i++) {
				y *= x;
			}
			return y;
		}
	}
}